package com.zhz.controller;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author ：zhz
 * @date ：Created in 2021/02/07
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description: 监听
 **/
@Component
public class ConsumerReceiver {
    //直连模式的多个消费者，会分到其中一个消费者进行消费。类似task模式
    //通过注入RabbitContainerFactory对象，来设置一些属性，相当于task里的channel.basicQos
    @RabbitListener(queues = "helloWorldQueue")
    public void helloWorldReceive(String message){
        System.out.println("hello world："+message);
    }
    //工作队列模式
    @RabbitListener(queues = "work_sb_mq_q")
    public void wordQueueReceiveQ1(String message){
        System.out.println("工作队列模式1："+message);
    }
    @RabbitListener(queues = "work_sb_mq_q")
    public void wordQueueReceiveQ2(String message){
        System.out.println("工作队列模式2："+message);
    }
    //pub/sub模式进行消息监听
    @RabbitListener(queues = "fanout.q1")
    public void fanoutReceiveQ1(String message){
        System.out.println("发布订阅模式1："+message);
    }
    @RabbitListener(queues = "fanout.q2")
    public void fanoutReceiveQ2(String message){
        System.out.println("发布订阅模式1："+message);
    }

    //Routing路由模式
    @RabbitListener(queues="direct_sb_mq_q1")
    public void routingReceiveQ1(String message) {

        System.out.println("Routing路由模式1: " +message);
    }

    @RabbitListener(queues="direct_sb_mq_q2")
    public void routingReceiveQ2(String message) {

        System.out.println("Routing路由模式2: " +message);
    }
    //topic 模式
    //注意这个模式会有优先匹配原则。例如发送routingKey=guangzhou.IT,那匹配到guangzhou.*(guangzhou.IT,guangzhou.eco),之后就不会再去匹配*.ITd
    @RabbitListener(queues="topic_sb_mq_q1")
    public void topicReceiveQ1(String message) {
        System.out.println("Topic模式1: " +message);
    }

    @RabbitListener(queues="topic_sb_mq_q2")
    public void topicReceiveQ2(String message) {
        System.out.println("Topic模式2: " +message);
    }

}
